// pages/order/xujieorder.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pid:0,
      goodDatas:[],
      pagenum:1
  },

    //获取续借订单
    getDataList:function(e){
    var that = this;
      wx.request({
          url:app.data.server+'/index.php/Tongcheng/Book/xujiedingdan?pid='+that.data.pid+"&pagenum="+that.data.pagenum,
          success:res=>{
            // console.log(JSON.stringify(res.data))
              that.setData({
                  goodDatas:that.data.goodDatas.concat(res.data)
              })
          }
      })
    },del:function(e){
        var that = this;
        var id = e.currentTarget.dataset.id;
        wx.showModal({
            title:'提示',
            content:'确定要删除吗？',
            showCancel:true,
            success:function(res){
                if (res.confirm) {
                    // console.log('用户点击确定')
                    wx.request({
                        url:getApp().data.server + '/index.php/Tongcheng/Book/delOrderById?id='+id,
                        success:function(e){
                            if(1 == e.data){
                                wx.showToast({
                                    title:'删除成功',
                                    icon: 'success',
                                    duration: 2000
                                })
                                that.setData({
                                    goodDatas:[],
                                    pagenum:1
                                })
                                that.getDataList();
                            }else{
                                wx.showToast({
                                    title:'删除失败',
                                    icon: 'success',
                                    duration: 2000
                                })
                            }
                        }
                    })
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
        pid:options.pid
    })
    console.log(options.pid);
  },

    onReachBottom: function (e) {
        // var that = this;
        // // 显示加载图标
        // wx.showLoading({
        //     title: '玩命加载中',
        // })
        // that.setData({
        //     pageNum:1,
        //     xieWenData:[]
        // })
        // this.getDataList();
    },
    onPullDownRefresh:function(e){
        // console.log('下拉刷新')
        wx.showLoading({
            title: '玩命加载中',
        })
        var that = this;
        that.setData({
            pagenum:that.data.pagenum+1

        })
        this.getDataList();
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      this.getDataList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})